import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.Date;

/** server with functionality as interpreted from assignment specifications.
 *  By Joseph Macaranas and Travis Turner
 */
public class server implements ServerInterface {

	public server() throws RemoteException {
		setupRMI();
	}
	
	private void setupRMI() {
        try {
        	ServerInterface stub = (ServerInterface) UnicastRemoteObject.exportObject((Remote) this);
        	Registry registry = LocateRegistry.createRegistry(1099); //default RMI port
        	registry.rebind("ServerInterface", stub);
        } catch (RemoteException re) {
        	re.printStackTrace();
        }
	}
	
	public ServiceReply SimpleService(int t1, int s1) throws RemoteException {
		try {
			long startTime = (new Date()).getTime();
			Thread.sleep(t1);
			ServiceReply sr = new ServiceReply();
			sr.reply = new char [s1];
			long endTime = (new Date()).getTime();
			System.out.println("Start time: " + startTime + " ms.");
			System.out.println("End time: " + endTime + " ms.");
			return sr;
		} catch (InterruptedException ie) {
			ie.printStackTrace();
			return null;
		}
	}
	
	public static void main(String [] args) {
		try {
			server s = new server();
		} catch (RemoteException re) {
			re.printStackTrace();
		}
	}
	
}
